package action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import service.service_admin.Service_Admin;
import service.service_public.Service_Public;
import service.service_search.Service_Search;
import tools.InterfaceDataPlaList;
import tools.InterfaceForResultSetToList;
import tools.PageBeanPlus;
import view.ViewOc_Data_Ice;
import view.ViewOc_Data_Pla;
import entitybean.l_sequence.EntityBeanL_Sequence;

import entitybean.oc_boat_ice.EntityBeanOc_Boat_Ice;
import entitybean.oc_boat_pla.EntityBeanOc_Boat_Pla;
import entitybean.oc_date_pla.EnitityBeanOc_Date_Pla;
import entitybean.oc_depthlist_ice.EntityBeanOc_Depthlist_Ice;
import entitybean.oc_depthlist_pla.EntityBeanOc_Depthlist_Pla;
import entitybean.oc_property_ice.EntityBean_Oc_Property_Ice;
import entitybean.oc_property_pla.EntityBean_Oc_Property_Pla;
import entitybean.oc_property_tools_ice.EntityBean_Oc_Property_Tools_Ice;
import entitybean.oc_property_tools_pla.EntityBean_Oc_Property_Tools_Pla;
import entitybean.oc_sea_area_pla.EntityBeanOc_Sea_Area_Pla;
import entitybean.oc_station_ice.EntityBeanOc_Station_Ice;
import entitybean.oc_station_pla.EntityBeanOc_Station_Pla;
import entitybean.oc_voyage_ice.EnitityBeanOc_Voyage_Ice;
import entitybean.oc_voyage_pla.EnitityBeanOc_Voyage_Pla;

import form.DataPlaForm;

public class Action_Oc_Data_Pla extends DispatchAction{
	private Service_Admin service_admin;
    private Service_Public service_public;
 	private Service_Search service_search;
	public ActionForward admin_init_oc_data_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataPlaForm boatIceForm = (DataPlaForm) form;
		String sql = "select ID,VALUE_KEY,"
			+ "(SELECT OC_DEPTHLIST_PLA.DEPTH FROM OC_DEPTHLIST_PLA WHERE OC_DEPLIST_ID=OC_DEPTHLIST_PLA.ID)OC_DEPLIST_ID,"
			+ "(SELECT OC_STATION_PLA.STATION_NAME FROM OC_STATION_PLA WHERE OC_STATION_ID=OC_STATION_PLA.ID)OC_STATION_ID,"
			+ "(SELECT OC_VOYAGE_PLA.VOYAGE_NAME FROM OC_VOYAGE_PLA WHERE OC_VOYAGE_ID=OC_VOYAGE_PLA.ID)OC_VOYAGE_ID,"
			+ "(SELECT OC_PROPERTY_PLA.PROPERTY_NAME FROM OC_PROPERTY_PLA WHERE OC_PROPERTY_ID=OC_PROPERTY_PLA.ID)OC_PROPERTY_ID,"
			+ "(SELECT OC_PROPERTY_TOOLS_PLA.TOOLS_NAME FROM OC_PROPERTY_TOOLS_PLA WHERE OC_PROPERTY_TOOLS_ID=OC_PROPERTY_TOOLS_PLA.ID)OC_PROPERTY_TOOLS_ID,"
			+ "(SELECT OC_BOAT_PLA.OC_BOATNAME FROM OC_BOAT_PLA WHERE (SELECT OC_VOYAGE_PLA.BOATID FROM OC_VOYAGE_PLA WHERE ID=OC_VOYAGE_ID)=OC_BOAT_PLA.ID) OC_BOAT_ID"
			+ " FROM OC_DATE_PLA where DEL='OFF' ORDER BY ID";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(boatIceForm.getRowcountperpage()), Integer
						.valueOf(boatIceForm.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data_Pla> list = interfaceforresultsettolist
		.ViewOc_Data_Pla(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("dataform", boatIceForm);
		return mapping.findForward("success");
	}

	public ActionForward admin_load_oc_data_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return null;
	}

	public ActionForward admin_add_data_pla(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		List<EntityBean_Oc_Property_Pla> property_list=service_search.Find_EntityBean_Oc_Property_Pla();

		List<EntityBeanOc_Boat_Pla> boat_list=service_search.Find_EntityBeanOc_Boat_Pla();
		List<EntityBeanOc_Depthlist_Pla> depthlist=service_search.Find_EntityBeanOc_Depthlist_Pla();


		request.setAttribute("depthlist", depthlist);
		request.setAttribute("boat_list", boat_list);
		request.setAttribute("property_list", property_list);
		return mapping.findForward("success");
	}

	public ActionForward admin_insert_data_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataPlaForm goodform = (DataPlaForm) form;
		Integer oc_boatname=goodform.getOc_deplist_id();
		Integer oc_boatkind=goodform.getOc_property_id();
		Integer oc_property_tools_id=goodform.getOc_property_tools_id();
		Integer oc_station_id=goodform.getOc_station_id();
		Integer oc_voyage_id=goodform.getOc_voyage_id();
		Double value_key=goodform.getValue_key();
		EnitityBeanOc_Date_Pla link=new EnitityBeanOc_Date_Pla();
        link.setOc_deplist_id(oc_boatname);
        link.setOc_property_id(oc_boatkind);
        link.setOc_property_tools_id(oc_property_tools_id);
        link.setOc_station_id(oc_station_id);
        link.setOc_voyage_id(oc_voyage_id);
        link.setValue_key(value_key);
        link.setOc_xls_upload(0);
		link.setDel("OFF");
		Integer i=0;
		EntityBeanL_Sequence entity=new EntityBeanL_Sequence();
		entity=this.service_public.Find_L_Sequence_By_seq_Name("SEQ_OC_DATA_PLA");
		i=entity.getSeq_Value()+1;
		entity.setSeq_Value(i);
		link.setId(i);
		this.service_public.Update_L_Sequence(entity);
		this.service_search.Insert_Oc_Data_Pla(link);
		System.out.println("初始化新闻模块");
		// 封装新闻查询的数据及表单
		DataPlaForm dataform = (DataPlaForm) form;
		dataform.setCurrentpage("1");
		String sql = "select ID,VALUE_KEY,"
			+ "(SELECT OC_DEPTHLIST_PLA.DEPTH FROM OC_DEPTHLIST_PLA WHERE OC_DEPLIST_ID=OC_DEPTHLIST_PLA.ID)OC_DEPLIST_ID,"
			+ "(SELECT OC_STATION_PLA.STATION_NAME FROM OC_STATION_PLA WHERE OC_STATION_ID=OC_STATION_PLA.ID)OC_STATION_ID,"
			+ "(SELECT OC_VOYAGE_PLA.VOYAGE_NAME FROM OC_VOYAGE_PLA WHERE OC_VOYAGE_ID=OC_VOYAGE_PLA.ID)OC_VOYAGE_ID,"
			+ "(SELECT OC_PROPERTY_PLA.PROPERTY_NAME FROM OC_PROPERTY_PLA WHERE OC_PROPERTY_ID=OC_PROPERTY_PLA.ID)OC_PROPERTY_ID,"
			+ "(SELECT OC_PROPERTY_TOOLS_PLA.TOOLS_NAME FROM OC_PROPERTY_TOOLS_PLA WHERE OC_PROPERTY_TOOLS_ID=OC_PROPERTY_TOOLS_PLA.ID)OC_PROPERTY_TOOLS_ID,"
			+ "(SELECT OC_BOAT_PLA.OC_BOATNAME FROM OC_BOAT_PLA WHERE (SELECT OC_VOYAGE_PLA.BOATID FROM OC_VOYAGE_PLA WHERE ID=OC_VOYAGE_ID)=OC_BOAT_PLA.ID) OC_BOAT_ID"
			+ " FROM OC_DATE_PLA where DEL='OFF' ORDER BY ID";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(dataform.getRowcountperpage()), Integer
						.valueOf(dataform.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data_Pla> list = interfaceforresultsettolist
				.ViewOc_Data_Pla(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("dataform", dataform);
		return mapping.findForward("success");
	}

	public ActionForward admin_delete_data_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataPlaForm boatIceForm = (DataPlaForm) form;
		String id = boatIceForm.getId();
		id = this.cut_tail(id);
		this.service_search.Delete_Oc_Data_Pla(id);

		String sql = "select ID,VALUE_KEY,"
			+ "(SELECT OC_DEPTHLIST_PLA.DEPTH FROM OC_DEPTHLIST_PLA WHERE OC_DEPLIST_ID=OC_DEPTHLIST_PLA.ID)OC_DEPLIST_ID,"
			+ "(SELECT OC_STATION_PLA.STATION_NAME FROM OC_STATION_PLA WHERE OC_STATION_ID=OC_STATION_PLA.ID)OC_STATION_ID,"
			+ "(SELECT OC_VOYAGE_PLA.VOYAGE_NAME FROM OC_VOYAGE_PLA WHERE OC_VOYAGE_ID=OC_VOYAGE_PLA.ID)OC_VOYAGE_ID,"
			+ "(SELECT OC_PROPERTY_PLA.PROPERTY_NAME FROM OC_PROPERTY_PLA WHERE OC_PROPERTY_ID=OC_PROPERTY_PLA.ID)OC_PROPERTY_ID,"
			+ "(SELECT OC_PROPERTY_TOOLS_PLA.TOOLS_NAME FROM OC_PROPERTY_TOOLS_PLA WHERE OC_PROPERTY_TOOLS_ID=OC_PROPERTY_TOOLS_PLA.ID)OC_PROPERTY_TOOLS_ID,"
			+ "(SELECT OC_BOAT_PLA.OC_BOATNAME FROM OC_BOAT_PLA WHERE (SELECT OC_VOYAGE_PLA.BOATID FROM OC_VOYAGE_PLA WHERE ID=OC_VOYAGE_ID)=OC_BOAT_PLA.ID) OC_BOAT_ID"
			+ " FROM OC_DATE_PLA where DEL='OFF' ORDER BY ID";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(boatIceForm.getRowcountperpage()), Integer
						.valueOf(boatIceForm.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data_Pla> list = interfaceforresultsettolist
		.ViewOc_Data_Pla(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("dataform", boatIceForm);
		return mapping.findForward("success");
	}
	public ActionForward admin_update_init_oc_data_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataPlaForm boatIceForm = (DataPlaForm) form;
		String id=boatIceForm.getId();
		EnitityBeanOc_Date_Pla e=this.service_search.Find_EnitityBeanOc_Date_Pla(Integer.valueOf(id));
		

		List<EntityBean_Oc_Property_Pla> property_list=service_search.Find_EntityBean_Oc_Property_Pla();

		
		List<EntityBeanOc_Boat_Pla> boat_list=service_search.Find_EntityBeanOc_Boat_Pla();
		
		List<EntityBeanOc_Depthlist_Pla> depthlist=service_search.Find_EntityBeanOc_Depthlist_Pla();

		


		Integer boat_id = this.service_search.Find_EnitityBeanOc_Voyage_Pla(e.getOc_voyage_id()).getBoatid();
		List<EnitityBeanOc_Voyage_Pla> voyage_list = this.service_search.Find_Oc_Voyage_Pla_By_boatid(boat_id);
		
		List<EntityBeanOc_Station_Pla>  station_list = this.service_search.Find_Oc_Station_Pla_by_oc_voyage_id(e.getOc_voyage_id());
		List<EntityBean_Oc_Property_Tools_Pla> property_tool_list = this.service_search.Find_EntityBean_Oc_Property_Tools_Pla_by_property_id(e
						.getOc_property_id());

		request.setAttribute("voyage_list", voyage_list);
		request.setAttribute("station_list", station_list);
		request.setAttribute("property_tool_list", property_tool_list);
		request.setAttribute("depthlist", depthlist);
		request.setAttribute("boat_list", boat_list);
		request.setAttribute("property_list", property_list);
		request.setAttribute("boat_id", boat_id);
		request.setAttribute("e", e);
		return mapping.findForward("success");
	}
	public ActionForward admin_update_oc_data_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataPlaForm goodform = (DataPlaForm) form;
		Integer oc_boatname=goodform.getOc_deplist_id();
		Integer oc_boatkind=goodform.getOc_property_id();
		Integer oc_property_tools_id=goodform.getOc_property_tools_id();
		Integer oc_station_id=goodform.getOc_station_id();
		Integer oc_voyage_id=goodform.getOc_voyage_id();
		Double value_key=goodform.getValue_key();
		String id=goodform.getId();
		EnitityBeanOc_Date_Pla link=new EnitityBeanOc_Date_Pla();
        link.setOc_deplist_id(oc_boatname);
        link.setOc_property_id(oc_boatkind);
        link.setOc_property_tools_id(oc_property_tools_id);
        link.setOc_station_id(oc_station_id);
        link.setOc_voyage_id(oc_voyage_id);
        link.setValue_key(value_key);
        link.setOc_xls_upload(0);
		link.setDel("OFF");
		link.setId(Integer.valueOf(id));
		this.service_search.Update_Oc_Data_Pla(link);
		DataPlaForm dataform = (DataPlaForm) form;
		dataform.setCurrentpage("1");
		String sql = "select ID,VALUE_KEY,"
			+ "(SELECT OC_DEPTHLIST_PLA.DEPTH FROM OC_DEPTHLIST_PLA WHERE OC_DEPLIST_ID=OC_DEPTHLIST_PLA.ID)OC_DEPLIST_ID,"
			+ "(SELECT OC_STATION_PLA.STATION_NAME FROM OC_STATION_PLA WHERE OC_STATION_ID=OC_STATION_PLA.ID)OC_STATION_ID,"
			+ "(SELECT OC_VOYAGE_PLA.VOYAGE_NAME FROM OC_VOYAGE_PLA WHERE OC_VOYAGE_ID=OC_VOYAGE_PLA.ID)OC_VOYAGE_ID,"
			+ "(SELECT OC_PROPERTY_PLA.PROPERTY_NAME FROM OC_PROPERTY_PLA WHERE OC_PROPERTY_ID=OC_PROPERTY_PLA.ID)OC_PROPERTY_ID,"
			+ "(SELECT OC_PROPERTY_TOOLS_PLA.TOOLS_NAME FROM OC_PROPERTY_TOOLS_PLA WHERE OC_PROPERTY_TOOLS_ID=OC_PROPERTY_TOOLS_PLA.ID)OC_PROPERTY_TOOLS_ID,"
			+ "(SELECT OC_BOAT_PLA.OC_BOATNAME FROM OC_BOAT_PLA WHERE (SELECT OC_VOYAGE_PLA.BOATID FROM OC_VOYAGE_PLA WHERE ID=OC_VOYAGE_ID)=OC_BOAT_PLA.ID) OC_BOAT_ID"
			+ " FROM OC_DATE_PLA where DEL='OFF' ORDER BY ID";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(dataform.getRowcountperpage()), Integer
						.valueOf(dataform.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data_Pla> list = interfaceforresultsettolist
		.ViewOc_Data_Pla(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("dataform", dataform);
		    return mapping.findForward("success");
	}

	public ActionForward admin_search_data_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataPlaForm boatIceForm = (DataPlaForm) form;
		String sql = "select ID,VALUE_KEY,"
			+ "(SELECT OC_DEPTHLIST_PLA.DEPTH FROM OC_DEPTHLIST_PLA WHERE OC_DEPLIST_ID=OC_DEPTHLIST_PLA.ID)OC_DEPLIST_ID,"
			+ "(SELECT OC_STATION_PLA.STATION_NAME FROM OC_STATION_PLA WHERE OC_STATION_ID=OC_STATION_PLA.ID)OC_STATION_ID,"
			+ "(SELECT OC_VOYAGE_PLA.VOYAGE_NAME FROM OC_VOYAGE_PLA WHERE OC_VOYAGE_ID=OC_VOYAGE_PLA.ID)OC_VOYAGE_ID,"
			+ "(SELECT OC_PROPERTY_PLA.PROPERTY_NAME FROM OC_PROPERTY_PLA WHERE OC_PROPERTY_ID=OC_PROPERTY_PLA.ID)OC_PROPERTY_ID,"
			+ "(SELECT OC_PROPERTY_TOOLS_PLA.TOOLS_NAME FROM OC_PROPERTY_TOOLS_PLA WHERE OC_PROPERTY_TOOLS_ID=OC_PROPERTY_TOOLS_PLA.ID)OC_PROPERTY_TOOLS_ID,"
			+ "(SELECT OC_BOAT_PLA.OC_BOATNAME FROM OC_BOAT_PLA WHERE (SELECT OC_VOYAGE_PLA.BOATID FROM OC_VOYAGE_PLA WHERE ID=OC_VOYAGE_ID)=OC_BOAT_PLA.ID) OC_BOAT_ID"
			+ " FROM OC_DATE_PLA where DEL='OFF' ORDER BY ID";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(boatIceForm.getRowcountperpage()), Integer
						.valueOf(boatIceForm.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data_Pla> list = interfaceforresultsettolist
		.ViewOc_Data_Pla(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("dataform", boatIceForm);
		return mapping.findForward("success");
	}

	private String cut_tail(String str) {
		String cut = str;
		if (str.endsWith(",")) {
			cut = cut.substring(0, cut.length() - 1);
		}
		return cut;
	}

	public Service_Admin getService_admin() {
		return service_admin;
	}

	public void setService_admin(Service_Admin service_admin) {
		this.service_admin = service_admin;
	}

	public Service_Public getService_public() {
		return service_public;
	}

	public void setService_public(Service_Public service_public) {
		this.service_public = service_public;
	}

	public Service_Search getService_search() {
		return service_search;
	}

	public void setService_search(Service_Search service_search) {
		this.service_search = service_search;
	}
}
